package com.csun.cmny.provider.controller.admin;

import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.domain.DmcRfidLabelRole;
import com.csun.cmny.provider.model.domain.DmcRfidLabelRoleTime;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.DmcRfidLabelRoleTimeService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2020-09-01 19:32
 * @Description:
 */
@RestController
@RequestMapping(value = "/rfidLabelRole", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class DmcRfidLabelRoleTimeController extends BaseController {

    @Resource
    private CmnyMessageSource cmnyMessageSource;
    @Resource
    private DmcRfidLabelRoleTimeService dmcRfidLabelRoleTimeService;


    /**
     * 设置时间段
     */
    @PostMapping(value = "/setTime")
    public Wrapper setTime(@RequestBody DmcRfidLabelRoleTime dmcRfidLabelRoleTime) {

        Integer result = dmcRfidLabelRoleTimeService.setTime(dmcRfidLabelRoleTime, getLoginAuthDto());
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /**
     * 设置时间段
     */
    @PostMapping(value = "/queryTimeList")
    public Wrapper queryTimeList(DmcRfidLabelRoleTime dmcRfidLabelRoleTime) {

        List<DmcRfidLabelRoleTime> dmcRfidLabelRoleTimeList = dmcRfidLabelRoleTimeService.select(dmcRfidLabelRoleTime);

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,
                cmnyMessageSource.getMessage("operation.success", null),
                dmcRfidLabelRoleTimeList);
    }

}
